<?php

/**
 * This object represents a collection that can contain CalDAV calendars.
 *
   * Copyright © 2010 Jack Cleaver
   * 
   * This plugin provides functionality added by CalDAV (RFC 4791)
   * It implements new reports, and the MKCALENDAR method.
   *
   * This file is part of Slash.
   *
   * Slash is free software: you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation, either version 3 of the License, or
   * (at your option) any later version.
   *
   * Slash is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   *
   * You should have received a copy of the GNU General Public License
   * along with Slash.  If not, see <http://www.gnu.org/licenses/>.
 */
class Slash_CalDAV_FSExt_CalendarRoot
extends Slash_CalDAV_FSExt_Directory
implements Sabre_DAV_IExtendedCollection
{

	function createCalendar($calendarName, array $properties)
	{
		Slash_Debug::debugDump("CalendarRoot createCalendar $calendarName: properties", $properties);
		$this->createDirectory($calendarName);
		$server = Slash_CalDAV_Server::getInstance();
		$basePath = $server->tree->getNodeForPath("/")->path;
		$thisUri = substr($this->path, strlen($basePath));
		//TODO: should check that this->path starts with basePath. 
		$calendarPath = $thisUri . "/" . $calendarName;
		Slash_Debug::debug("CalendarRoot createCalendar: Getting node for $calendarPath");
		$node = $server->tree->getNodeForPath($calendarPath);
		$node->updateProperties($properties);
	}

	function createExtendedCollection($name, array $resourceType, array $properties)
	{
		if (!in_array('{urn:ietf:params:xml:ns:caldav}calendar',$resourceType) || count($resourceType)!==2) 
		{
			throw new Sabre_DAV_Exception_InvalidResourceType('Unknown resourceType for this collection');
		}
		$this->createCalendar($name, $properties);
	}

}
